package com.cheney.diandireader.server.action;

import java.io.File;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.cheney.diandireader.server.domain.AttachFile;
import com.cheney.diandireader.server.service.FileManageService;
import com.cheney.diandireader.server.utils.DiandiReaderServerConfig;

/**
 * used to create/update/delete folder 
 * @author mayh
 *
 */
@Controller
@RequestMapping("/fileManage")
public class FileManageAction {
	
	@Autowired
	private FileManageService fileManageService;
	
	//list file
	@RequestMapping("/list")
	public ModelAndView list(String superId){
		superId = superId == null? "":superId;
		ModelAndView mv = new ModelAndView("/fileManage/list");
		List<AttachFile> fileList = fileManageService.listBySuperId(superId);
		mv.addObject("list", fileList);
		return mv;
	}
	
	//list file
	@RequestMapping(value="/newFolder")
	public ModelAndView newFolder(AttachFile attachFile){
		File file = new File(DiandiReaderServerConfig.basePath+"/"+attachFile.getSuperAttachFile().getPath()+"/"+attachFile.getPath());
		System.out.println(file.getPath());
		ModelAndView mv = new ModelAndView("fileManage/list");
		return mv;
	}
}
